//角色编辑
var groupid;
var iconid;
var subid;
var menuid;
var index = "";
$(function(){
	 groupid = ly.getUrlParam("groupid");
	 iconid = ly.getUrlParam("iconid");
	 subid = ly.getUrlParam("subid");
	 menuid = ly.getUrlParam("menuid");
	//构建列表
	$('#rolelist').getList({
		"initData":{
			"num":1,
			"size":10,
		},
		"url":site.apiUrl+"/role/selectRoleList",// 数据请求url
		"type":"POST",
		"ajaxform":true,
		// "checkname":"chk1",
		"col":[  //数据列
			{"field":"roleName","display":"角色名称"},	
			// {"field":"roleIcon","display":"角色图标","width":"2","fun":"changePic"},
			{"field":"attrStr","display":"角色状态"},
			//{"field":"attr5Str","display":"是否允许管理终端"},
			{"field":"createTime","display":"创建时间","width":"2"},
		],
		"option":[ //操作按钮配置
			{"icon":"setrules","tip":"设置权限","url":"set_role.html?id={{id}}&roleName={{roleName}}"},  // 花括号内可以对应相关字段
			{"icon":"edit","tip":"编辑","url":"add-role.html?id={{id}}"},  // 花括号内可以对应相关字段
			{"icon":"del","tip":"删除","fun":"deleteRole('{{id}}')"}
		]
	});
});

//删除
function deleteRole(id){
	var deleteUserId = window.localStorage.getItem("backstage-access-id");
	var obj = {
		'id':id,
		'deleteUserId':deleteUserId
	};
	var url = site.apiUrl+"/role/deleteRole";
	ly.confirm("你确定删除吗？",function(){
		request({
	        url: url,
	        data:obj,
	        type: 'POST',
	        ajaxform:true,
	        callback: function(r) {
				if(r.code=="rest.success"){
					ly.toast('删除成功');
					$("#rolelist").getList.refresh();//刷新当前分页
	        	}else{
					ly.toast(data.result);
	        	}
	        }
		});
	});
}
